package com.person.jiaiplan.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.person.jiaiplan.pojo.R;
import com.person.jiaiplan.pojo.dto.SummaryReportReqDTO;
import com.person.jiaiplan.pojo.dto.SummaryReportResDTO;
import com.person.jiaiplan.pojo.dto.summary.*;
import com.person.jiaiplan.service.SummaryReportService;
import com.person.jiaiplan.util.ExcelUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 总结汇报
 */
@AllArgsConstructor
@RestController
@RequestMapping("summaryReport")
@Validated
public class SummaryReportController {

    @Autowired
    private SummaryReportService summaryReportService;

    @PostMapping("/query")
    public R<IPage<SummaryReportResDTO>> query(@RequestBody SummaryReportReqDTO summaryReportReqDTO) {
        return R.ok(summaryReportService.query(summaryReportReqDTO));
    }

    /**
     * 获取周总结
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/getWeeklySummary")
    public R getWeeklySummary(@RequestBody WeeklySummaryReqDTO reqDTO, HttpServletResponse response) {
        List<WeeklySummaryResDTO> excelData = summaryReportService.getWeeklySummary(reqDTO);
        return new ExcelUtils(excelData, response, WeeklySummaryResDTO.class).weeklySummaryTableFill(reqDTO, excelData, response);
    }


    /**
     * 获取年度报告总结
     *
     * @param reqDTO
     * @param response
     * @return
     */
    @PostMapping("/getAnnualSummary")
    public R getAnnualSummary(@RequestBody AnnualSummaryReqDTO reqDTO, HttpServletResponse response) {
        List<AnnualSummaryResDTO> excelData = summaryReportService.getAnnualSummary(reqDTO);
        AnnualSummaryCountResDTO annualSummaryCountResDTO = summaryReportService.getAnnualSummaryCount(excelData);
        return new ExcelUtils(excelData, response, AnnualSummaryResDTO.class).annualSummaryTableFill(reqDTO, excelData, annualSummaryCountResDTO, response);
    }

}
